<?php
if(!interface_exists('XTable', false)){
	require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'XTable.php');
}
class XBasicTable implements XTable{
	protected $columns = array();
	protected $PK = null;
	protected $name = null;
	
	/**
	 * @return XBasicTable
	 */	
	public function setColumns(array $columns){
		$this->columns = $columns;
		return $this;
	}
	
	public function columns(){
		return $this->columns;
	}
	
	public function column($key){
		return x_array_get($this->columns, $key);
	}
	
	/**
	 * @return XBasicTable
	 */	
	public function setPK($PK){
		$this->PK = $PK;
		return $this;
	}
	
	public function PK(){
		return $this->PK;
	}
	
	/**
	 * @return XBasicTable
	 */
	public function setName($name) {
		$this->name = $name;
		return $this;
	}

	public function name() {
		return $this->name;
	}	
	
	public function validate(){
		if(empty($this->columns)
			|| count($this->columns) == 0){
			throw new XORMException("table {$this->name} metadata init error.");
		}
		if(!$this->PK){
			throw new XORMException("table {$this->name} doesn't have a primary key.");
		}
	}
}
?>